package com.bank.trade_records.cun_money.controller;


import com.bank.trade_records.cun_money.entity.CunMoney;
import com.bank.trade_records.cun_money.service.CunMoneyService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/tradeRecords/CunMoney")
public class CunMoneyController {

    @Autowired
    private CunMoneyService cunMoneyService;

    // 获取单个用户
    @GetMapping("/{id}")
    public CunMoney getCunMoneyById(@PathVariable Long id) {
        return cunMoneyService.getCunMoneyById(id);
    }

    // 添加用户
    @PostMapping
    public boolean addCunMoney(@RequestBody CunMoney cunMoney) {
        return cunMoneyService.addCunMoney(cunMoney);
    }

    // 更新用户
    @PutMapping("/{id}")
    public boolean updateCunMoney(@PathVariable Long id,@RequestBody CunMoney cunMoney) {
        cunMoney.setId(id); // 假设前端传来的CunMoney对象不包含ID，需要手动设置
        return cunMoneyService.updateCunMoney(cunMoney);
    }

    // 删除用户
    @DeleteMapping("/{id}")
    public boolean deleteCunMoneyById(@PathVariable Long id) {
        return cunMoneyService.deleteCunMoneyById(id);
    }

    // 获取所有用户
    @GetMapping
    public List<CunMoney> getAllCunMoneys() {
        return cunMoneyService.getAllCunMoneys();
    }

    // 批量插入用户
    @PostMapping("/batch")
    public boolean batchInsert(@RequestBody List<CunMoney> cunMoneyList) {
        return cunMoneyService.batchInsert(cunMoneyList);
    }

    @GetMapping("/page")
    public Page<CunMoney> getCunMoneyPage(@RequestParam(value = "page", defaultValue = "1") int page,
                                        @RequestParam(value = "size", defaultValue = "10") int size) {
        Page<CunMoney> cunMoneyPage = new Page<>(page, size);
        return cunMoneyService.getCunMoneyPage(cunMoneyPage);
    }

    @PostMapping("/sum")
    public List<Object> getDailyTransactionAmounts(){
        return cunMoneyService.getDailyTransactionAmounts();
    };


    // 其他接口...
}
